home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / The Hacks! / Transport Independent Speech / SpokenSerialApp / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-21  |  2.2 KB  |  110 lines  |  [TEXT/CWIE]

  1. #ifndef __MAIN__
  2. #include "main.h"
  3. #endif
  4.  
  5. //Globals
  6.     Boolean                gDone            = false;
  7.     SpeechChannel        theSpeechChan    = nil;
  8.     Byte                formingByte;
  9.     Boolean                inputBufferHalfByte;
  10.     
  11. void main (void)
  12. {
  13.     SpeechInfoStruct    theSpeechInfo;
  14.     EventRecord            event;
  15.     OSErr                theErr            = noErr;
  16.     Boolean                gotEvent        = false;
  17.     DriverRefNum        proxyInRefNum, proxyOutRefNum;
  18.     ToolBoxInit ();
  19.  
  20.     theErr = SpeakWelcome ();
  21.     if (theErr == noErr) {
  22.         theErr = ListenToUser (&theSpeechInfo);
  23.     }
  24.  
  25.     
  26.     inputBufferHalfByte = false;
  27.     formingByte = 0;
  28.     
  29.     while (theErr == noErr && (gDone == false || SpeechBusy() != 0)) {    //Don't quit if we're talking to you
  30.         gotEvent = WaitNextEvent (everyEvent, &event, 6, nil);
  31.         if (gotEvent) {
  32.             switch (event.what)
  33.             {
  34.                 case keyDown:
  35.                     gDone = true;    //want to be able to quit if speech recognition isn't working
  36.                     break;
  37.                 case kHighLevelEvent :
  38.                     AEProcessAppleEvent (&event);    //Handle speech recognition events
  39.                     break;
  40.                 case mouseUp:
  41.                 case mouseDown:
  42.                 case keyUp:
  43.                 case autoKey:
  44.                 case updateEvt:
  45.                 case diskEvt:
  46.                 case activateEvt:
  47.                 case osEvt:
  48.                     break;
  49.             }
  50.         }
  51.     }
  52.  
  53.     theErr = SRCloseRecognitionSystem (theSpeechInfo.recogSystem);
  54. }
  55.  
  56. OSErr        SpeakWelcome        (void)
  57. {
  58.     OSErr                theErr            = noErr;
  59.  
  60.     theErr = GetNewSpeechChan (&theSpeechChan);        //Set up a global speech channel
  61.  
  62.     return theErr;
  63. }
  64.  
  65. OSErr        ListenToUser        (SpeechInfoPtr theSpeechInfo)
  66. {
  67.     OSErr                theErr            = noErr;
  68.  
  69.     theSpeechInfo->ID                = 'myID';
  70.     theSpeechInfo->recogSystem        = 0;
  71.     theSpeechInfo->theRecognizer    = 0;
  72.     theSpeechInfo->languages        = nil;
  73.     theSpeechInfo->SpeechDoneUPP    = nil;
  74.     theSpeechInfo->attributes        = 0;
  75.  
  76.     theErr = InitSpeechRecognition (theSpeechInfo);
  77.  
  78.     if (theErr == noErr) {
  79.         theErr = OpenSpeechRecognition (theSpeechInfo);
  80.     }
  81.  
  82.     if (theErr == noErr) {
  83.         theErr = ConfigureRecognition (theSpeechInfo);
  84.     }
  85.  
  86.     if (theErr == noErr) {
  87.         theErr = GetNewRecognizer (theSpeechInfo);
  88.     }
  89.  
  90.     if (theErr == noErr) {
  91.         theErr = SetSpeechDoneAEHander (theSpeechInfo);
  92.     }
  93.  
  94.     if (theErr == noErr) {
  95.         theErr = InstallRecogAEHandler (theSpeechInfo);
  96.     }
  97.  
  98.     if (theErr == noErr) {
  99.         theErr = MakeNewLanguage (theSpeechInfo);
  100.     }
  101.  
  102.     if (theErr == noErr) {
  103.         theErr = SRStartListening (theSpeechInfo->theRecognizer);
  104.     }
  105.  
  106.     return theErr;
  107. }
  108.  
  109.  
  110.